package com.msb.dp.strategy;

import java.util.Arrays;

/**
 * @Auther: Huanyu Lee
 * @Date: 2022/3/3  17:12
 * @Description: 测试策略模式
 */
public class Main{
    public static void main(String[] args) {
        // 对int[] 数组排序
        Integer[] a = {9, 7, 2, 5, 9, 2, 1, 3};
        Sorter<Integer> s1 = new Sorter<>();
        s1.sort(a, (o1,o2)->{
            if (o1 > o2) return -1;
            else if (o1 < o2)   return 1;
            return 0;
        });
        System.out.println(Arrays.toString(a));

        // 对double[] 数组排序
        Double[] b = {3.7, 9.7, 1.2, 2.6, 8.4, 3.0};
        Sorter<Double> s2 = new Sorter<>();
        s2.sort(b,(o1,o2)->{
            if (o1 > o2) return -1;
            else if (o1 < o2)   return 1;
            return 0;
        });
        System.out.println(Arrays.toString(b));
        // 对Cat[] 数组排序
        Cat[] cats = {
                new Cat(1,3),
                new Cat(1,2),
                new Cat(2,4),
                new Cat(3,5),
        };
        Sorter<Cat> s3 = new Sorter<>();
        s3.sort(cats,new CatHeightComparator());
        System.out.println(Arrays.toString(cats));

        s3.sort(cats,new CatWeightComparator());
        System.out.println(Arrays.toString(cats));

        // 对Dog[] 数组排序
        Dog[] dogs = {
                new Dog(2),
                new Dog(1),
                new Dog(3),
        };
        Sorter<Dog> s4 = new Sorter<>();
        s4.sort(dogs,new DogComparator());
        System.out.println(Arrays.toString(dogs));
    }
}
